﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetWebInfo
{
    class Const
    {
        /// <summary>
        /// 测试模式下读取本地文件
        /// </summary>
        public static bool OnlyTest = false;


        /* 
         * 【2011第一季度】http://stockdata.stock.hexun.com/2008/zcfz.aspx?stockid=600016&accountdate=2011.03.15
         * 【2011第二季度】http://stockdata.stock.hexun.com/2008/zcfz.aspx?stockid=600016&accountdate=2011.06.30
         * 【2011第三季度】http://stockdata.stock.hexun.com/2008/zcfz.aspx?stockid=600016&accountdate=2011.09.30
         * 【2011第四季度】http://stockdata.stock.hexun.com/2008/zcfz.aspx?stockid=600016&accountdate=2011.12.31
         * http://stockdata.stock.hexun.com/2008/lr.aspx?stockid=600195&accountdate=2010.12.31
         * http://stockdata.stock.hexun.com/2008/xjll.aspx?stockid=600195&accountdate=2010.12.31
         */
        //hexun balance
        public const string PagePath_HexunStatement_zcfz = "http://stockdata.stock.hexun.com/2008/zcfz.aspx?stockid={0}&accountdate={1}";
        //operations
        public const string PagePath_HexunStatement_lr = "http://stockdata.stock.hexun.com/2008/lr.aspx?stockid={0}&accountdate={1}";
        //cashflow
        public const string PagePath_HexunStatement_xjll = "http://stockdata.stock.hexun.com/2008/xjll.aspx?stockid={0}&accountdate={1}";
        public const string PagePath_HexunStatement_all = "http://stockdata.stock.hexun.com/2009_zcfz_{0}.shtml";
        public const string PagePath_HexunDividend = "http://stockdata.stock.hexun.com/2009_fhzzgb_{0}.shtml";

        /*
         * http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600195.phtml?year=2012&jidu=1
         * http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600195.phtml?year=2011&jidu=4
         */
        public const string PagePath_SinaPrice_all = "http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/{0}.phtml";
        public const string PagePath_SinaPrice = "http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/{0}.phtml?year={1}&jidu={2}";

        public static string Code = string.Empty;

        public static string Path = string.Empty;

        

        public const string PriceFileName = "SharePrice";

        public const string DividendFileName = "Dividend";

        public const string ReportExtName = ".json";

        public const string ReportTempExtName = ".json.temp";
    }

    class Global
    {
        public static string StringReplaces(string oldstr, Dictionary<string, string> kvps)
        {
            foreach (KeyValuePair<string, string> kvp in kvps)
            {
                oldstr = oldstr.Replace(kvp.Key.ToString(), kvp.Value.ToString());
            }
            return oldstr;
        }

        public static bool IsValueFormat(string valueString)
        {
            bool hexFormat = true;

            foreach (char digit in valueString)
            {
                if (!IsSNDigit(digit))
                {
                    hexFormat = false;
                    break;
                }
            }
            return hexFormat;
        }

        public static bool IsSNDigit(Char c)
        {
            int numChar;
            int numA = Convert.ToInt32('-');
            int numB = Convert.ToInt32('.');
            int num1 = Convert.ToInt32('0');
            c = Char.ToUpper(c);
            numChar = Convert.ToInt32(c);
            if (numChar == numA || numChar == numB)
                return true;
            if (numChar >= num1 && numChar < (num1 + 10))
                return true;
            return false;
        }
    }
}
